<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Story extends CI_Controller
{
	public function main()
	{

	}

	public function create()
	{
		if ($_POST) {
			// 基础数据
			$post = array(
				'title' => $this->input->post('title'),
				'images' => $this->input->post('images'),
				'category_id' => $this->input->post('category_id'),
				'author' => $this->input->post('author'),
				'keyword' => $this->input->post('keyword'),
				'description' => $this->input->post('description'),
				'create_time' => time(),
				'update_time' => time(),
			);

			// 基础数据添加
			$result = $this->Story_model->insert($post);
			if ($result) {
				$msg = array(
					'message' => '添加成功',
					'waitSecond' => 1,
					'jumpUrl' => '/index.php/bm/story/index'
				);
				$this->load->view('message/success', $msg);
			}
		} else {
			// 获取数组
			$categoryList = $this->StoryCategory_model->lists();
			// 转换格式
			$tree_to_select = tree_to_select($categoryList);
			// 获取小说作家
			$authorList = $this->Author_model->lists();
			// 转换格式
			$author_tree_to_select = tree_to_select($authorList);

			// 赋值
			$data = array(
				'tree_to_select' => $tree_to_select,
				'author_tree_to_select' => $author_tree_to_select,
			);

			$this->load->view('bm/story/create', $data);
		}
	}
}
